package fun.stgoder.test1;

public class TestQ2 {

    static Thread t1, t2;

    public static void main(String[] args) {

        char[] arr = new char[]{
                'A', 'B', 'C', 'D', 'E', 'F', 'G',
                'H', 'I', 'J', 'K', 'L', 'M', 'N',
                'O', 'P', 'Q', 'R', 'S', 'T',
                'U', 'V', 'W', 'X', 'Y', 'Z',
        };

        Object o = new Object();

        t1 = new Thread(() -> {
            for (int i = 0; i < arr.length; i++) {

                synchronized (o) {
                    System.out.print(arr[i]);
                    o.notify();
                    try {
                        o.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

            }
        });


        t2 = new Thread(() -> {
            for (int i = 0; i < arr.length; i++) {

                synchronized (o) {
                    try {
                        o.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.print(i + 1);
                    o.notify();
                }

            }
        });


        t2.start();

        TestUtil.sleepSeconds(1);

        t1.start();
    }
}
